/*
 * @Date: 2024-12-02 13:39:21
 * @Author: LiSong
 * @LastEditors: LiSong
 * @LastEditTime: 2024-12-02 13:59:21
 * @Description: 
 */

import PojoUtils from '../utils/PojoUtils'

/**
 * 请求类型定义
 */
export class RequestType {
  constructor (label, value, order) {
    this.label=label
    this.value=value
    this.order=order
  }

  static get GET() {
    return new RequestType('GET', 'GET', 2)
  }
  static get POST() {
    return new RequestType('POST', 'POST', 1)
  }

  static getTypes () {
    const types = PojoUtils.getOwnPropertyStatics(this, true)
    return types.sort((a, b) => a.order - b.order)
  }

  /**
   * 比对是否相同
   * 
   * @param {Object|String} item 需要比对的数据
   * @returns {Boolean} true-相同 false-不相同
   */
  equals (item) {
    if (item instanceof RequestType) {
      return item.value === this.value
    } else {
      return item === this.value
    }
  }
}

/**
 * 请求类型定义
 */
export class RequestDataType {
  constructor (label, value, order) {
    this.label=label
    this.value=value
    this.order=order
  }

  static get DATA() {
    return new RequestDataType('data', 'data', 1)
  }
  static get PARAMS() {
    return new RequestDataType('params', 'params', 2)
  }

  static getTypes () {
    const types = PojoUtils.getOwnPropertyStatics(this, true)
    return types.sort((a, b) => a.order - b.order)
  }

  /**
   * 比对是否相同
   * 
   * @param {Object|String} item 需要比对的数据
   * @returns {Boolean} true-相同 false-不相同
   */
  equals (item) {
    if (item instanceof RequestDataType) {
      return item.value === this.value
    } else {
      return item === this.value
    }
  }
}